package com.godpaper.chessGameHall.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.godpaper.chessGameHall.events.JoinRoomEvent;
	
	import it.gotoandplay.smartfoxserver.SFSEvent;
	
	import mx.rpc.IResponder;
	
	public class JoinRoomCommand extends CommandBase implements ICommand, IResponder
	{
		private var joinRoomEvent:JoinRoomEvent;
		public function JoinRoomCommand()
		{
			super();
		}
		
		override public function execute(event:CairngormEvent):void
		{
			joinRoomEvent = JoinRoomEvent(event);
			this.sfClient.joinRoom( joinRoomEvent.newRoom,joinRoomEvent.pword );
			this.sfClient.addEventListener(SFSEvent.onJoinRoom,joinRoomHandler);
			this.sfClient.addEventListener(SFSEvent.onJoinRoomError,joinRoomErrorHandler);
		}
		/*
		* Handler a join room event
		*
		* For game rooms, efore we can use the components in the "view_game" screen 
		* of the viewstack we have to wait for them to initialize.
		*
		* This happens once only, so we keep a flag called "gameViewInited" to check
		* if this is the first time we show the game screen
		*
		* The initGame method is automatically called by the view_cgame Canvas component
		* when it fires the creationComplete event
		*/
		private function joinRoomHandler(event:SFSEvent):void
		{
			trace(event);
		}
		private function joinRoomErrorHandler(event:SFSEvent):void
		{
			trace(event);
		}
		
	}
}